package com.atguigu.petstore.shop.rpc;

import com.atguigu.petstore.common.result.Result;
import com.atguigu.petstore.shop.entity.ShopCategory;
import com.atguigu.petstore.shop.entity.ShopProduct;
import com.atguigu.petstore.shop.service.ShopCategoryService;
import com.atguigu.petstore.shop.service.ShopProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lfy
 * @Description
 * @create 2023-09-28 10:24
 */
@Tag(name = "商品RPC")
@RequestMapping("/rpc/shop")
@RestController
public class ShopRpcController {


    @Autowired
    ShopCategoryService shopCategoryService;

    @Autowired
    ShopProductService shopProductService;



    @Operation(summary = "获取商品分类树")
    @GetMapping("/category/tree")
    public Result<List<ShopCategory>> getShopCategoryTree(){

        List<ShopCategory> categoryTree = shopCategoryService.getCategoryTree();

        return Result.ok(categoryTree);
    }

    @Operation(summary = "获取秒杀商品")
    @GetMapping("/product/seckill")
    public Result<List<ShopProduct>> getSeckillProduct(){

        //获取秒杀商品
        List<ShopProduct> products =  shopProductService.getSeckillProduct();

        return Result.ok(products);
    }

    @Operation(summary = "获取排行榜商品")
    @GetMapping("/product/ranks")
    public Result<List<ShopProduct>> getRankProduct() {

        List<ShopProduct> ranks =  shopProductService.getRankProduct();
        return Result.ok(ranks);
    }

}
